<template>
  <div class="docs-page">
    <Header />
    
    <!-- Hero Section -->
    <section class="hero">
      <div class="container">
        <div class="hero-content">
          <h1 class="hero-title">使用文档</h1>
          <p class="hero-subtitle">
            详细的使用指南和配置说明，帮助您快速上手 Wu-Lazy-Cloud-Network
          </p>
        </div>
      </div>
    </section>

    <!-- Docs Navigation -->
    <section class="docs-navigation">
      <div class="container">
        <div class="docs-nav">
          <div class="nav-item" @click="scrollToSection('quick-start')">
            <el-icon><Timer /></el-icon>
            <span>快速开始</span>
          </div>
          <div class="nav-item" @click="scrollToSection('installation')">
            <el-icon><Download /></el-icon>
            <span>安装部署</span>
          </div>
          <div class="nav-item" @click="scrollToSection('configuration')">
            <el-icon><Setting /></el-icon>
            <span>配置说明</span>
          </div>
          <div class="nav-item" @click="scrollToSection('usage')">
            <el-icon><Document /></el-icon>
            <span>使用指南</span>
          </div>
          <div class="nav-item" @click="scrollToSection('troubleshooting')">
            <el-icon><Tools /></el-icon>
            <span>故障排除</span>
          </div>
        </div>
      </div>
    </section>

    <!-- Quick Start -->
    <section class="docs-section" id="quick-start">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">快速开始</h2>
          <p class="section-subtitle">几分钟内完成部署和配置</p>
        </div>
        
        <div class="docs-content">
          <div class="step-guide">
            <div class="step">
              <div class="step-number">1</div>
              <div class="step-content">
                <h3>启动服务端</h3>
                <p>使用 Docker 快速启动服务端</p>
                <div class="code-block">
                  <pre><code class="language-bash">docker run -d -it -p 6001:6001 -p 7001:7001 -p 8001:8001 -p 9001:9001 \
  --name wlcn-server \
  registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.3.4-JDK24-SNAPSHOT</code></pre>
                </div>
                <div class="step-notes">
                  <h4>端口说明</h4>
                  <ul>
                    <li><strong>6001</strong>: Web 管理界面</li>
                    <li><strong>7001</strong>: TCP 连接端口</li>
                    <li><strong>8001</strong>: HTTP 代理端口</li>
                    <li><strong>9001</strong>: SOCKS 代理端口</li>
                  </ul>
                </div>
              </div>
            </div>
            
            <div class="step">
              <div class="step-number">2</div>
              <div class="step-content">
                <h3>启动客户端</h3>
                <p>配置客户端连接到服务端</p>
                <div class="code-block">
                  <pre><code class="language-bash">docker run -d -it --privileged -p 6004:6004 \
  --name wlcn-client \
  --restart=always \
  -e spring.lazy.netty.client.inet-host=YOUR_SERVER_IP \
  -e spring.lazy.netty.client.inet-port=7001 \
  -e spring.lazy.netty.client.client-id="your-client-id" \
  registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.4-JDK24-SNAPSHOT</code></pre>
                </div>
                <div class="step-notes">
                  <h4>环境变量说明</h4>
                  <ul>
                    <li><strong>inet-host</strong>: 服务端 IP 地址</li>
                    <li><strong>inet-port</strong>: 服务端 TCP 端口</li>
                    <li><strong>client-id</strong>: 客户端唯一标识</li>
                  </ul>
                </div>
              </div>
            </div>
            
            <div class="step">
              <div class="step-number">3</div>
              <div class="step-content">
                <h3>访问管理界面</h3>
                <p>通过 Web 界面进行配置和管理</p>
                <div class="code-block">
                  <pre><code class="language-bash"># 服务端管理界面
http://127.0.0.1:6001/netty-server-ui/index.html

# 客户端管理界面
http://127.0.0.1:6004/netty-client-local-ui/index.html</code></pre>
                </div>
                <div class="step-notes">
                  <h4>默认登录信息</h4>
                  <ul>
                    <li><strong>用户名</strong>: admin</li>
                    <li><strong>密码</strong>: admin</li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- Installation -->
    <section class="docs-section" id="installation">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">安装部署</h2>
          <p class="section-subtitle">支持多种部署方式，满足不同环境需求</p>
        </div>
        
        <div class="docs-content">
          <div class="deployment-methods">
            <div class="method-card">
              <div class="method-header">
                <el-icon><Box /></el-icon>
                <h3>Docker 部署</h3>
              </div>
              <p>推荐使用 Docker 进行部署，简单快速</p>
              <div class="method-steps">
                <h4>服务端部署</h4>
                <div class="code-block">
                  <pre><code class="language-bash"># 拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.3.4-JDK24-SNAPSHOT

# 启动容器
docker run -d -it -p 6001:6001 -p 7001:7001 -p 8001:8001 -p 9001:9001 \
  --name wlcn-server \
  registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.3.4-JDK24-SNAPSHOT</code></pre>
                </div>
                
                <h4>客户端部署</h4>
                <div class="code-block">
                  <pre><code class="language-bash"># 拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.4-JDK24-SNAPSHOT

# 启动容器
docker run -d -it --privileged -p 6004:6004 \
  --name wlcn-client \
  --restart=always \
  -e spring.lazy.netty.client.inet-host=YOUR_SERVER_IP \
  -e spring.lazy.netty.client.inet-port=7001 \
  -e spring.lazy.netty.client.client-id="your-client-id" \
  registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.4-JDK24-SNAPSHOT</code></pre>
                </div>
              </div>
            </div>
            
            <div class="method-card">
              <div class="method-header">
                <el-icon><Download /></el-icon>
                <h3>源码部署</h3>
              </div>
              <p>从源码编译部署，适合开发环境</p>
              <div class="method-steps">
                <h4>环境要求</h4>
                <ul>
                  <li>JDK 24 或 JDK 17+</li>
                  <li>Maven 3.6+</li>
                  <li>MySQL 8.0+ (可选)</li>
                </ul>
                
                <h4>编译部署</h4>
                <div class="code-block">
                  <pre><code class="language-bash"># 克隆项目
git clone https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
cd wu-lazy-cloud-network

# 编译项目
mvn clean package -DskipTests

# 启动服务端
cd wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-server-start
java -jar target/wu-lazy-cloud-heartbeat-server-start-1.3.4-JDK24-SNAPSHOT.jar

# 启动客户端
cd ../wu-lazy-cloud-heartbeat-client-start
java -jar target/wu-lazy-cloud-heartbeat-client-start-1.3.4-JDK24-SNAPSHOT.jar</code></pre>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- Configuration -->
    <section class="docs-section" id="configuration">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">配置说明</h2>
          <p class="section-subtitle">详细的配置参数说明和使用示例</p>
        </div>
        
        <div class="docs-content">
          <div class="config-tabs">
            <el-tabs v-model="activeConfigTab">
              <el-tab-pane label="服务端配置" name="server">
                <div class="config-content">
                  <h3>服务端配置</h3>
                  <div class="code-block">
                    <pre><code class="language-yaml">spring:
  lazy:
    netty:
      server:
        mode: standalone  # 模式：standalone/cluster
        node-id: default  # 节点ID
        node-host: 127.0.0.1  # 节点主机
        node-port: 7001  # 节点端口
        enable-flow-control: true  # 启用流量控制
        enable-token-verification: false  # 启用Token验证
        tcp:
          port: 7001  # TCP端口
        udp:
          port: 7001  # UDP端口</code></pre>
                  </div>
                  
                  <h4>配置参数说明</h4>
                  <div class="param-table">
                    <table>
                      <thead>
                        <tr>
                          <th>参数</th>
                          <th>说明</th>
                          <th>默认值</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td>mode</td>
                          <td>运行模式，支持 standalone 和 cluster</td>
                          <td>standalone</td>
                        </tr>
                        <tr>
                          <td>node-id</td>
                          <td>节点唯一标识</td>
                          <td>default</td>
                        </tr>
                        <tr>
                          <td>node-host</td>
                          <td>节点主机地址</td>
                          <td>127.0.0.1</td>
                        </tr>
                        <tr>
                          <td>node-port</td>
                          <td>节点监听端口</td>
                          <td>7001</td>
                        </tr>
                        <tr>
                          <td>enable-flow-control</td>
                          <td>是否启用流量控制</td>
                          <td>true</td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
              </el-tab-pane>
              
              <el-tab-pane label="客户端配置" name="client">
                <div class="config-content">
                  <h3>客户端配置</h3>
                  <div class="code-block">
                    <pre><code class="language-yaml">spring:
  lazy:
    netty:
      client:
        client-id: your-client-id  # 客户端ID
        inet-host: 127.0.0.1  # 服务端地址
        inet-port: 7001  # 服务端端口
        enable: true  # 启用客户端连接</code></pre>
                  </div>
                  
                  <h4>配置参数说明</h4>
                  <div class="param-table">
                    <table>
                      <thead>
                        <tr>
                          <th>参数</th>
                          <th>说明</th>
                          <th>默认值</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td>client-id</td>
                          <td>客户端唯一标识</td>
                          <td>-</td>
                        </tr>
                        <tr>
                          <td>inet-host</td>
                          <td>服务端 IP 地址</td>
                          <td>127.0.0.1</td>
                        </tr>
                        <tr>
                          <td>inet-port</td>
                          <td>服务端 TCP 端口</td>
                          <td>7001</td>
                        </tr>
                        <tr>
                          <td>enable</td>
                          <td>是否启用客户端连接</td>
                          <td>true</td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
              </el-tab-pane>
              
              <el-tab-pane label="代理配置" name="proxy">
                <div class="config-content">
                  <h3>代理配置</h3>
                  <div class="code-block">
                    <pre><code class="language-yaml">spring:
  lazy:
    netty:
      protocol:
        proxy:
          authentication: true  # 启用代理认证
          enable-proxy-log: false  # 启用代理日志
          socket-protocol-proxy:
            port: 9001  # SOCKS代理端口
          http-protocol-proxy:
            port: 8001  # HTTP代理端口</code></pre>
                  </div>
                  
                  <h4>配置参数说明</h4>
                  <div class="param-table">
                    <table>
                      <thead>
                        <tr>
                          <th>参数</th>
                          <th>说明</th>
                          <th>默认值</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td>authentication</td>
                          <td>是否启用代理认证</td>
                          <td>true</td>
                        </tr>
                        <tr>
                          <td>enable-proxy-log</td>
                          <td>是否启用代理日志</td>
                          <td>false</td>
                        </tr>
                        <tr>
                          <td>socket-protocol-proxy.port</td>
                          <td>SOCKS 代理端口</td>
                          <td>9001</td>
                        </tr>
                        <tr>
                          <td>http-protocol-proxy.port</td>
                          <td>HTTP 代理端口</td>
                          <td>8001</td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
      </div>
    </section>

    <!-- Usage Globe -->
    <section class="docs-section" id="usage">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">使用指南</h2>
          <p class="section-subtitle">详细的功能使用说明和最佳实践</p>
        </div>
        
        <div class="docs-content">
          <div class="usage-guides">
            <div class="guide-card">
              <h3>内网穿透配置</h3>
              <div class="guide-content">
                <h4>服务端渗透客户端</h4>
                <ol>
                  <li>在服务端管理界面配置端口池</li>
                  <li>设置访客端口与客户端真实端口的映射关系</li>
                  <li>例如：访客端口 19080 → 客户端本地端口 18080</li>
                  <li>通过 <code>http://服务端IP:19080</code> 访问客户端本地 18080 端口</li>
                </ol>
                
                <h4>客户端渗透服务端</h4>
                <ol>
                  <li>在客户端管理界面配置本地端口池</li>
                  <li>设置本地端口到远程端口的映射关系</li>
                  <li>例如：本地端口 13306 → 远程端口 3306</li>
                  <li>通过 <code>localhost:13306</code> 访问远程 3306 端口</li>
                </ol>
              </div>
            </div>
            
            <div class="guide-card">
              <h3>代理功能使用</h3>
              <div class="guide-content">
                <h4>HTTP 代理</h4>
                <ul>
                  <li><strong>服务端代理</strong>: 127.0.0.1:8001</li>
                  <li><strong>客户端代理</strong>: 127.0.0.1:8002</li>
                </ul>
                
                <h4>SOCKS 代理</h4>
                <ul>
                  <li><strong>服务端代理</strong>: 127.0.0.1:9001</li>
                  <li><strong>客户端代理</strong>: 127.0.0.1:9002</li>
                </ul>
                
                <h4>代理配置示例</h4>
                <div class="code-block">
                  <pre><code class="language-bash"># 系统代理设置 (Mac)
networksetup -setwebproxy "Wi-Fi" 127.0.0.1 8001
networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 8001

# 使用 curl 测试代理
curl -x http://127.0.0.1:8001 http://httpbin.org/ip</code></pre>
                </div>
              </div>
            </div>
            
            <div class="guide-card">
              <h3>流量监控</h3>
              <div class="guide-content">
                <h4>监控功能</h4>
                <ul>
                  <li>实时监控每个客户端的流量使用情况</li>
                  <li>按端口统计流量数据</li>
                  <li>提供流量趋势图表</li>
                  <li>支持流量告警设置</li>
                </ul>
                
                <h4>报表功能</h4>
                <ul>
                  <li>日流量统计报表</li>
                  <li>客户端流量排行</li>
                  <li>端口使用情况分析</li>
                  <li>历史数据查询</li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- Troubleshooting -->
    <section class="docs-section" id="troubleshooting">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">故障排除</h2>
          <p class="section-subtitle">常见问题解决方案和调试技巧</p>
        </div>
        
        <div class="docs-content">
          <div class="troubleshooting-list">
            <div class="trouble-item">
              <h3>客户端连接失败</h3>
              <div class="trouble-content">
                <h4>检查项</h4>
                <ul>
                  <li>服务端 IP 和端口是否正确</li>
                  <li>网络连接是否正常</li>
                  <li>防火墙是否阻止连接</li>
                </ul>
                
                <h4>解决方案</h4>
                <div class="code-block">
                  <pre><code class="language-bash"># 检查网络连接
ping YOUR_SERVER_IP

# 检查端口是否开放
telnet YOUR_SERVER_IP 7001

# 查看客户端日志
docker logs wlcn-client</code></pre>
                </div>
              </div>
            </div>
            
            <div class="trouble-item">
              <h3>内网穿透不工作</h3>
              <div class="trouble-content">
                <h4>检查项</h4>
                <ul>
                  <li>端口映射配置是否正确</li>
                  <li>目标服务是否正在运行</li>
                  <li>防火墙规则是否允许</li>
                </ul>
                
                <h4>解决方案</h4>
                <ul>
                  <li>确认映射配置: 访客端口 → 客户端端口</li>
                  <li>检查目标服务状态</li>
                  <li>测试本地端口访问</li>
                </ul>
              </div>
            </div>
            
            <div class="trouble-item">
              <h3>代理连接失败</h3>
              <div class="trouble-content">
                <h4>检查项</h4>
                <ul>
                  <li>代理地址和端口是否正确</li>
                  <li>代理认证信息是否正确</li>
                  <li>网络连接是否正常</li>
                </ul>
                
                <h4>解决方案</h4>
                <ul>
                  <li>验证代理配置信息</li>
                  <li>检查认证设置</li>
                  <li>测试网络连接</li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <Footer />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'
import { 
  Timer, 
  Download, 
  Setting, 
  Document, 
  Tools,
  Box
} from '@element-plus/icons-vue'

const activeConfigTab = ref('server')

const scrollToSection = (sectionId) => {
  const element = document.getElementById(sectionId)
  if (element) {
    element.scrollIntoView({ behavior: 'smooth' })
  }
}

onMounted(() => {
  // 高亮代码块
  if (window.Prism) {
    window.Prism.highlightAll()
  }
})
</script>

<style lang="scss" scoped>
.docs-page {
  min-height: 100vh;
}

// Hero Section
.hero {
  padding: 120px 0 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
  
  .hero-title {
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 16px;
    
    @media (max-width: 768px) {
      font-size: 32px;
    }
  }
  
  .hero-subtitle {
    font-size: 18px;
    opacity: 0.9;
    max-width: 600px;
    margin: 0 auto;
  }
}

// Docs Navigation
.docs-navigation {
  background: white;
  border-bottom: 1px solid var(--border-light);
  padding: 20px 0;
  position: sticky;
  top: 70px;
  z-index: 100;
}

.docs-nav {
  display: flex;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
  
  .nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-regular);
    
    &:hover {
      background: var(--background-light);
      color: var(--primary-color);
    }
    
    .el-icon {
      font-size: 18px;
    }
    
    span {
      font-weight: 500;
    }
  }
}

// Section Header
.section-header {
  text-align: center;
  margin-bottom: 60px;
  
  .section-title {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    
    @media (max-width: 768px) {
      font-size: 28px;
    }
  }
  
  .section-subtitle {
    font-size: 18px;
    color: var(--text-regular);
    max-width: 600px;
    margin: 0 auto;
  }
}

// Docs Section
.docs-section {
  padding: 80px 0;
  
  &:nth-child(even) {
    background: var(--background-light);
  }
}

.docs-content {
  max-width: 1000px;
  margin: 0 auto;
}

// Step Globe
.step-guide {
  .step {
    display: flex;
    gap: 20px;
    margin-bottom: 40px;
    
    .step-number {
      width: 40px;
      height: 40px;
      background: var(--primary-color);
      color: white;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 600;
      flex-shrink: 0;
    }
    
    .step-content {
      flex: 1;
      
      h3 {
        font-size: 20px;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 8px;
      }
      
      p {
        color: var(--text-regular);
        margin-bottom: 16px;
      }
      
      .step-notes {
        margin-top: 16px;
        
        h4 {
          font-size: 16px;
          font-weight: 600;
          color: var(--text-primary);
          margin-bottom: 8px;
        }
        
        ul {
          list-style: none;
          
          li {
            color: var(--text-regular);
            margin-bottom: 4px;
            position: relative;
            padding-left: 16px;
            
            &::before {
              content: '•';
              position: absolute;
              left: 0;
              color: var(--primary-color);
            }
          }
        }
      }
    }
  }
}

// Deployment Methods
.deployment-methods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 30px;
}

.method-card {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: var(--shadow-light);
  
  .method-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    
    .el-icon {
      font-size: 24px;
      color: var(--primary-color);
    }
    
    h3 {
      font-size: 20px;
      font-weight: 600;
      color: var(--text-primary);
    }
  }
  
  p {
    color: var(--text-regular);
    margin-bottom: 20px;
  }
  
  .method-steps {
    h4 {
      font-size: 16px;
      font-weight: 600;
      color: var(--text-primary);
      margin-bottom: 12px;
    }
    
    ul {
      list-style: none;
      margin-bottom: 16px;
      
      li {
        color: var(--text-regular);
        margin-bottom: 6px;
        position: relative;
        padding-left: 16px;
        
        &::before {
          content: '•';
          position: absolute;
          left: 0;
          color: var(--primary-color);
        }
      }
    }
  }
}

// Config Tabs
.config-tabs {
  .config-content {
    h3 {
      font-size: 20px;
      font-weight: 600;
      color: var(--text-primary);
      margin-bottom: 16px;
    }
    
    h4 {
      font-size: 16px;
      font-weight: 600;
      color: var(--text-primary);
      margin: 20px 0 12px;
    }
  }
}

// Parameter Table
.param-table {
  margin-top: 20px;
  
  table {
    width: 100%;
    border-collapse: collapse;
    
    th, td {
      padding: 12px;
      text-align: left;
      border-bottom: 1px solid var(--border-light);
    }
    
    th {
      background: var(--background-light);
      font-weight: 600;
      color: var(--text-primary);
    }
    
    td {
      color: var(--text-regular);
    }
  }
}

// Usage Globes
.usage-guides {
  display: grid;
  gap: 30px;
}

.guide-card {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: var(--shadow-light);
  
  h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
  }
  
  .guide-content {
    h4 {
      font-size: 16px;
      font-weight: 600;
      color: var(--text-primary);
      margin: 16px 0 8px;
    }
    
    ol, ul {
      color: var(--text-regular);
      margin-bottom: 16px;
      
      li {
        margin-bottom: 6px;
        line-height: 1.5;
      }
    }
    
    code {
      background: var(--background-light);
      padding: 2px 6px;
      border-radius: 4px;
      font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
      font-size: 14px;
    }
  }
}

// Troubleshooting
.troubleshooting-list {
  display: grid;
  gap: 30px;
}

.trouble-item {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: var(--shadow-light);
  
  h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
  }
  
  .trouble-content {
    h4 {
      font-size: 16px;
      font-weight: 600;
      color: var(--text-primary);
      margin: 16px 0 8px;
    }
    
    ul {
      list-style: none;
      margin-bottom: 16px;
      
      li {
        color: var(--text-regular);
        margin-bottom: 6px;
        position: relative;
        padding-left: 16px;
        
        &::before {
          content: '•';
          position: absolute;
          left: 0;
          color: var(--primary-color);
        }
      }
    }
  }
}
</style> 